/**
 * customerdepartment服务实现
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.service.impl;


import com.sxf.crm.entity.CustomerDepartment;
import com.sxf.crm.repository.CustomerDepartmentRepository;
import com.sxf.crm.service.CustomerDepartmentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 客户部门关系服务实现类
 * 
 * <p>实现客户与部门之间关联关系的业务逻辑</p>
 * 
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/6/1
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class CustomerDepartmentServiceImpl implements CustomerDepartmentService {

    private final CustomerDepartmentRepository customerDepartmentRepository;

    @Override
    @Transactional
    public CustomerDepartment create(CustomerDepartment customerDepartment) {
        log.info("开始创建客户部门关系: customerId={}, departmentId={}", 
            customerDepartment.getCustomer().getId(), 
            customerDepartment.getDepartment().getId());
            
        CustomerDepartment saved = customerDepartmentRepository.save(customerDepartment);
        
        log.info("客户部门关系创建成功: {}", saved);
        return saved;
    }
} 